﻿import win32ui
import win32api
import win32con
from pywin.mfc import dialog

def MakeLoginDlgTemplate(title, userid):
	style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
	cs = win32con.WS_CHILD | win32con.WS_VISIBLE

	# Window frame and title
	dlg = [ [title, (0, 0, 150, 85), style, None, (9, "Gulim")], ]

	# Email label and text box
	dlg.append([130, u"한RSS 이메일".encode('mbcs'), -1, (7, 9, 45, 9), cs | win32con.SS_RIGHT])
	s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER 
	dlg.append([129, userid, win32ui.IDC_EDIT1, (57, 7, 80, 12), s | win32con.ES_AUTOHSCROLL])

	# Password label and text box
	dlg.append([130, u"비밀번호".encode('mbcs'), -1, (7, 24, 45, 9), cs | win32con.SS_RIGHT])
	s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER 
	dlg.append([129, None, win32ui.IDC_EDIT2, (57, 22, 80, 12), s | win32con.ES_PASSWORD | win32con.ES_AUTOHSCROLL])

	# Checkbox
	s = cs | win32con.WS_TABSTOP
	dlg.append([128, u"서버에서 중요한 글 제거".encode('mbcs'), win32ui.IDC_CHECK1, (33, 42, 100, 9), s | win32con.BS_AUTOCHECKBOX])

	# OK/Cancel Buttons
	s = cs | win32con.WS_TABSTOP 
	dlg.append([128, u"확인".encode('mbcs'), win32con.IDOK, (33, 60, 40, 14), s | win32con.BS_DEFPUSHBUTTON])
	s = win32con.BS_PUSHBUTTON | s
	dlg.append([128, u"취소".encode('mbcs'), win32con.IDCANCEL, (78, 60, 40, 14), s])
	return dlg

class LoginDlg(dialog.Dialog):
	def __init__(self, title, userid):
		dialog.Dialog.__init__(self, MakeLoginDlgTemplate(title, userid))
		self.AddDDX(win32ui.IDC_EDIT1,'userid')
		self.AddDDX(win32ui.IDC_EDIT2,'password')
		self.AddDDX(win32ui.IDC_CHECK1,'empty')

	def OnInitDialog(self):
		button = self.GetDlgItem(win32ui.IDC_CHECK1)
		#button.SetCheck(1)

def GetLogin(title='Login', userid=''):
	d = LoginDlg(title, userid)
	if d.DoModal() != win32con.IDOK:
		return (None, None, None)
	else:	
		return (d['userid'], d['password'], d['empty'])

if __name__ == "__main__":
	import sys
	title = u'로그인'.encode('mbcs')
	def_userid = ''
	if len(sys.argv) > 1:
		title = sys.argv[1]
	if len(sys.argv) > 2:
		def_userid = sys.argv[2]
	userid, password, empty = GetLogin(title, def_userid)
	if userid == password == None:
		print "User pressed Cancel"
	else:
		print "User ID: ", userid
		print "Password:", password
		print "Empty:", empty
